<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="菜单编号"  align="center"></el-table-column>
      <el-table-column prop="title" label="菜单名称" align="center"></el-table-column>

      <el-table-column label="菜单图标" align="center">
        <template slot-scope="scope">
          <i :class="scope.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"    align="center"></el-table-column>
      <el-table-column label="状态"    align="center">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作"    align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="bianji(scope.row.id)">编辑</el-button>
          <el-button type="danger" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { reqmenudelete } from "../../../request/api";
import { successAlert } from "../../../utils/alert";
export default {
  props: ["list"],
  data() {
    return {};
  },
  methods: {
    //删除功能
      del(id) {
      this.$confirm("你确定要删除吗?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          reqmenudelete({id:id}).then(res=>{
            if(res.data.code==200){
              successAlert(res.data.msg)
              this.$emit("init")
            }
          })
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //点击编辑 子传父 自定义事件edi 携带参数id
    bianji(id) {
      this.$emit("edit", id);
    },
  },
};
</script>

<style>
</style>